package com.cloudsea.yunhaianalysis.controller;

import com.cloudsea.yunhaianalysis.entity.Warnings;
import com.cloudsea.yunhaianalysis.service.WarningService;
import com.cloudsea.yunhaiutils.common.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "商家-智能预警")
@RestController
@RequestMapping("/warnings")
public class WarningController {
    @Autowired
    private WarningService warningService;
    @Operation(summary = "获取最新的未读预警")
    @GetMapping("/latest")
    public ApiResponse<List<Warnings>> getLatestUnread(@RequestParam Long storeId) {
        return ApiResponse.success(warningService.getLatestUnreadWarnings(storeId));
    }

    @Operation(summary = "将单条预警标记为已读")
    @PostMapping("/{warningId}/read")
    public ApiResponse<Void> markWarningAsRead(
            @Parameter(description = "要标记为已读的预警ID", required = true)
            @PathVariable Long warningId
    ) {
        warningService.markAsRead(warningId);
        return ApiResponse.success("标记成功", null);
    }

    @Operation(summary = "一键标记所有预警为已读")
    @PostMapping("/read-all")
    public ApiResponse<Void> markAllWarningsAsRead(
            @Parameter(description = "要操作的门店ID", required = true)
            @RequestParam Long storeId
    ) {
        warningService.markAllAsRead(storeId);
        return ApiResponse.success("全部已读操作成功", null);
    }
}
